package cn.edu.cug.cs.gtl.docsrv.auth.dao.imp;

import cn.edu.cug.cs.gtl.docsrv.config.Configuration;
import cn.edu.cug.cs.gtl.docsrv.auth.dao.LoginDao;
import cn.edu.cug.cs.gtl.mybatis.Session;
import cn.edu.cug.cs.gtl.mybatis.mapper.auth.AuthUser;
import cn.edu.cug.cs.gtl.mybatis.mapper.auth.AuthUserMapper;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Component
public class LoginDaoImpl implements LoginDao {
    @Override
    public AuthUser getUser(String userName) throws Exception {
        Session s = Configuration.getSession();
        AuthUserMapper authUserMapper=s.getMapper(AuthUserMapper.class);
        AuthUser authUser=authUserMapper.selectByUserName(userName);
        s.close();
        return authUser;
    }

    @Override
    public AuthUser getUser(long userInternalId) throws Exception {
        Session s = Configuration.getSession();
        AuthUserMapper authUserMapper=s.getMapper(AuthUserMapper.class);
        AuthUser authUser=authUserMapper.selectByPrimaryKey(BigDecimal.valueOf(userInternalId));
        s.close();
        return authUser;
    }
}
